 Imports System.Windows.Forms
 Public Class QUYENCHITIETdto
 Inherits AbstractDto 
 #Region "Các Thuộc Tính" 
 Private _iD as System.Int32
 Private _Quyen as System.Int32
 Private _TenForm as System.String
 Private _TenButon as System.String
 Private _Trangthai as System.Int32
 Private _Ghichu as System.String
 #End Region 
 #Region "Khai báo các phương thức truy xuất" 
 Public Property iD() as System.Int32
 Get
 Return _iD
 End Get
 Set(ByVal value As System.Int32)
 _iD=Value
 End Set
 End Property
 Public Property Quyen() as System.Int32
 Get
 Return _Quyen
 End Get
 Set(ByVal value As System.Int32)
 _Quyen=Value
 End Set
 End Property
 Public Property TenForm() as System.String
 Get
 Return _TenForm
 End Get
 Set(ByVal value As System.String)
 _TenForm=Value
 End Set
 End Property
 Public Property TenButon() as System.String
 Get
 Return _TenButon
 End Get
 Set(ByVal value As System.String)
 _TenButon=Value
 End Set
 End Property
 Public Property Trangthai() as System.Int32
 Get
 Return _Trangthai
 End Get
 Set(ByVal value As System.Int32)
 _Trangthai=Value
 End Set
 End Property
 Public Property Ghichu() as System.String
 Get
 Return _Ghichu
 End Get
 Set(ByVal value As System.String)
 _Ghichu=Value
 End Set
 End Property
 #End Region 
 Public Sub New()
iD = 0
Quyen = 0
TenForm = "
TenButon = "
Trangthai = 0
Ghichu = "
 End Sub
 public Function HoTro(ByVal tencolumn As String) As String
 Select Case Ucase(Convert.ToString(tencolumn))
 Case Ucase("iD")
 if IsDBNull(iD)=true then 
 return "0"
 end if
 Return Convert.ToString(iD)
 Case Ucase("Quyen")
 if IsDBNull(Quyen)=true then 
 return "0"
 end if
 Return Convert.ToString(Quyen)
 Case Ucase("TenForm")
 if IsDBNull(TenForm)=true then 
 return """
 end if
 Return Convert.ToString(TenForm)
 Case Ucase("TenButon")
 if IsDBNull(TenButon)=true then 
 return """
 end if
 Return Convert.ToString(TenButon)
 Case Ucase("Trangthai")
 if IsDBNull(Trangthai)=true then 
 return "0"
 end if
 Return Convert.ToString(Trangthai)
 Case Ucase("Ghichu")
 if IsDBNull(Ghichu)=true then 
 return """
 end if
 Return Convert.ToString(Ghichu)
 Case Else
 Return ""
 End Select
 End Function
 public function HoTro(ByVal tencolumn As String,Byval value as string,Optional ByVal TT As String = "sua") as string 
 Select Case Ucase(Convert.ToString(tencolumn))
 Case UCase("iD")
 If TT = "sua" Then
 If IsDBNull(value) = true Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If value = ""  Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If IsNumeric(value) = False Then
 return "Không phải số đề nghị nhập lại"
end if
iD=CInt(value)
End if
 Case UCase("Quyen")
 If IsDBNull(value) = true Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If value = ""  Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If IsNumeric(value) = False Then
 return "Không phải số đề nghị nhập lại"
end if
Quyen=CInt(value)
 Case UCase("TenForm")
 If IsDBNull(value) = true Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If value = ""  Then
 return "Bạn chưa nhập dữ liệu"
 End if
TenForm=Convert.ToString(value)
 Case UCase("TenButon")
 If IsDBNull(value) = true Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If value = ""  Then
 return "Bạn chưa nhập dữ liệu"
 End if
TenButon=Convert.ToString(value)
 Case UCase("Trangthai")
 If IsDBNull(value) = true Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If value = ""  Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If IsNumeric(value) = False Then
 return "Không phải số đề nghị nhập lại"
end if
Trangthai=CInt(value)
 Case UCase("Ghichu")
 If IsDBNull(value) = true Then
 return "Bạn chưa nhập dữ liệu"
 End if
 If value = ""  Then
 return "Bạn chưa nhập dữ liệu"
 End if
Ghichu=Convert.ToString(value)
 Case Else
 return ""
 End Select
 return ""
 End function
 Public Sub GANgiatri(ByVal Group As Control, Optional ByVal TAG As String = "")
 Dim ValControl As New Control
 For Each ValControl In Group.Controls
 If ValControl.Visible And ValControl.Enabled Then
 If (TAG = "" Or ValControl.Tag = TAG) Then
 Dim str As String = Me.HoTro(UCase(Mid(ValControl.Name, 4)))
 If str <> "" Then
 If TypeOf (ValControl) Is TextBox Or TypeOf (ValControl) Is Label Then
 ValControl.Text = Str
 ElseIf TypeOf (ValControl) Is NumericUpDown Then
 Dim NUD As NumericUpDown = ValControl
 NUD.Value = Str
 ElseIf TypeOf (ValControl) Is DateTimePicker Then
 Dim DTP As DateTimePicker = ValControl
 DTP.Value = Str
 ElseIf TypeOf (ValControl) Is ComboBox Then
 Dim cbo As ComboBox = ValControl
 cbo.SelectedValue = Str
 ElseIf TypeOf (ValControl) Is PictureBox Then
 Dim pic As PictureBox = ValControl
 pic.ImageLocation = Str
 End If
 End If
 End If
 If ValControl.Controls.Count > 0 Then GANgiatri(ValControl, TAG)
 End If
 Next
 End Sub
 Public Sub NHANgiatri(ByVal Group As Control, ByVal ErrorProvider1 As ErrorProvider, Optional ByVal TAG As String = "")
 Dim ValControl As New Control
 Dim loi As String = ""
 For Each ValControl In Group.Controls
 If ValControl.Visible And ValControl.Enabled Then
 If (TAG = "" Or ValControl.Tag = TAG) Then
 If TypeOf (ValControl) Is TextBox Or TypeOf (ValControl) Is Label Then
 loi = Me.HoTro(UCase(Mid(ValControl.Name, 4)), ValControl.Text)
 ElseIf TypeOf (ValControl) Is ComboBox Then
 Dim cbo As ComboBox = ValControl
 loi = Me.HoTro(UCase(Mid(cbo.Name, 4)), cbo.SelectedValue)
 ElseIf TypeOf (ValControl) Is NumericUpDown Then
 Dim NUD As NumericUpDown = ValControl
 loi = Me.HoTro(UCase(Mid(ValControl.Name, 4)), NUD.Value)
 ElseIf TypeOf (ValControl) Is DateTimePicker Then
 Dim dtp As DateTimePicker = ValControl
 loi = Me.HoTro(UCase(Mid(ValControl.Name, 4)), dtp.Value)
 ElseIf TypeOf (ValControl) Is PictureBox Then
 Dim pic As PictureBox = ValControl
 loi = Me.HoTro(UCase(Mid(ValControl.Name, 4)), pic.ImageLocation)
 End If
 If loi <> "" Then
 ValControl.Focus()
 End If
 ErrorProvider1.SetError(ValControl, loi)
 End If
 If ValControl.Controls.Count > 0 Then
 NHANgiatri(ValControl, ErrorProvider1, TAG)
 End If
 End If
 Next
 End Sub
 End class

